package com.thread.www.demo;

import java.util.HashMap;

/**
 * Created by 27340 on 2017/11/25.
 */
public class DeadLock {
    static Byte lock1 = new Byte("1");
    static Byte lock2 = new Byte("2");
    public static class Demo{
        public  void a(){
            synchronized(lock1){
                System.out.println("in a");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                b();
            }

        }

        public void b(){
            synchronized(lock2){
                System.out.println("in b");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                a();
            }
        }

    }

    public static void main(String[] args) {
        HashMap map = new HashMap();
        map.put("1",1);
//        final Demo d = new Demo();
        final DeadLock.Demo d1 = new DeadLock.Demo();
        Thread t1 = new Thread(new Runnable(){
            @Override
            public void run() {
                d1.a();
            }
        });

        Thread t2 = new Thread(new Runnable(){
            @Override
            public void run() {
                d1.b();
            }
        });
        t1.start();
        t2.start();

    }
}
